#include <cstdio>
#include <cstring>
#include <queue>

const int N = 2000005;
int n, m, tot, id[N], ans[N];
int e_cnt, heads[N];
int trie[200005][26], fail[200005];
char s[N];

struct Edge {
  int v, nxt;
} e[N];

inline void add(int u, int v) { e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt; }

inline void insert(char *str, int _id) {
  int n = strlen(str), cur = 0;
  for (int i = 0; i < n; ++i) {
    int ch = str[i] - 'a';
    if (!trie[cur][ch]) trie[cur][ch] = ++tot;
    cur = trie[cur][ch];
  }
  id[_id] = cur;
}

inline void query(char *str) {
  int cur = 0, n = strlen(str);
  for (int i = 0; i < n; ++i) {
    cur = trie[cur][str[i] - 'a'];
    ++ans[cur];
  }
}

inline void getfail() {
  std::queue<int> q;
  for (int i = 0; i < 26; ++i) {
    if (trie[0][i]) {
      q.push(trie[0][i]);
    }
  }
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (register int i = 0, v; i < 26; ++i) {
      if ((v = trie[x][i])) {
        q.push(trie[x][i]);
        fail[v] = trie[fail[x]][i];
      } else
        trie[x][i] = trie[fail[x]][i];
    }
  }
}

void dfs(int x) {
  for (int i = heads[x]; i; i = e[i].nxt) {
    int v = e[i].v;
    dfs(v);
    ans[x] += ans[v];
  }
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#endif
#ifndef LOCAL
  freopen("ACAutoMaton(TS).in", "r", stdin);
  freopen("ACAutoMaton(TS).out", "w", stdout);
#endif
#endif

  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s);
    insert(s, i);
  }
  scanf("%s", s);	
  getfail();
  query(s);
  for (int i = 1; i <= tot; ++i) {
    add(fail[i], i);
  }
  dfs(0);
  for (int i = 1; i <= n; ++i) {
    printf("%d\n", ans[id[i]]);
  }
  return 0;
}